home *** CD-ROM | disk | FTP | other *** search
- package symantec.itools.db.awt;
-
- import java.awt.Checkbox;
- import java.awt.CheckboxGroup;
- import java.awt.Component;
- import java.awt.Container;
- import java.io.IOException;
- import java.util.Vector;
- import symantec.itools.db.pro.ProjBinder;
- import symantec.itools.db.pro.ProjLink;
- import symantec.itools.db.pro.RelationView;
- import symjava.sql.SQLException;
-
- public class RadioBox extends CheckboxGroup implements ProjLink {
- private ProjBinder m_ProjBinder;
- private RelationView m_relView;
- private String m_projection;
- private int m_treatBlankAs;
- private boolean m_DynamicUpdate = false;
- private Vector rbkVector = new Vector();
- private Container m_Container;
-
- public RadioBox(Container c) {
- this.m_Container = c;
- }
-
- public void init(ProjBinder binder) {
- this.m_ProjBinder = binder;
- }
-
- public RelationView getRelView() {
- return this.m_relView;
- }
-
- public String getProjection() {
- return this.m_projection;
- }
-
- public void setTreatBlankAs(String blank) {
- if ((new String(blank)).toUpperCase().equals("DEFAULT")) {
- this.m_treatBlankAs = 0;
- } else if ((new String(blank)).toUpperCase().equals("NULL")) {
- this.m_treatBlankAs = 1;
- } else {
- if ((new String(blank)).toUpperCase().equals("EMPTY")) {
- this.m_treatBlankAs = 2;
- }
-
- }
- }
-
- public void setBinding(RelationView relView, String projection) {
- this.m_relView = relView;
- this.m_projection = projection;
-
- try {
- int projectionNumber = relView.findProjByName(projection);
- relView.bindProj(projectionNumber, this);
- } catch (SQLException Ex) {
- this.raiseException("SQLException from RadioBox.setBinding: " + ((Throwable)Ex).getMessage());
- }
- }
-
- void addCheckboxes(Container c) {
- int compCnt = c.countComponents();
- Component[] compArray = new Component[compCnt];
- compArray = c.getComponents();
-
- for(int loops = 0; loops < compArray.length; ++loops) {
- if (compArray[loops] instanceof RadioButton) {
- this.rbkVector.addElement(compArray[loops]);
- }
- }
-
- }
-
- public void notifyDataChange(ProjBinder binder) {
- int rbCurrent = 0;
- boolean itemfound = false;
- this.addCheckboxes(this.m_Container);
-
- try {
- while(rbCurrent < this.rbkVector.size()) {
- RadioButton rb = (RadioButton)this.rbkVector.elementAt(rbCurrent);
- if (rb != null) {
- if (((Checkbox)rb).getLabel().equals(binder.getStringValue())) {
- itemfound = true;
- break;
- }
-
- ++rbCurrent;
- }
- }
- } catch (SQLException Ex) {
- this.raiseException("SQLException from RadioBox.notifyDataChange: " + ((Throwable)Ex).getMessage());
- } catch (IOException Ex) {
- this.raiseException("IOException from RadioBox.notifyDataChange: " + ((Throwable)Ex).getMessage());
- }
-
- if (!itemfound) {
- ((CheckboxGroup)this).setCurrent((Checkbox)null);
- }
-
- }
-
- public boolean notifySetData(ProjBinder binder) throws SQLException {
- return this.notifyStateChange();
- }
-
- boolean notifyStateChange() {
- if (((CheckboxGroup)this).getCurrent() == null) {
- try {
- if (this.m_ProjBinder != null && this.m_ProjBinder.isWritable()) {
- this.m_ProjBinder.setValueFromString("", 0, this.m_treatBlankAs);
- }
- } catch (SQLException Ex) {
- this.raiseException("SQLException from RadioBox.notifyStateChange: " + ((Throwable)Ex).getMessage());
- return false;
- } catch (IOException Ex) {
- this.raiseException("IOException from RadioBox.notifyStateChange: " + ((Throwable)Ex).getMessage());
- return false;
- }
- }
-
- return true;
- }
-
- void raiseException(String text) {
- System.out.println(text);
- }
-
- public void setDynamicUpdate(boolean update) {
- this.m_DynamicUpdate = update;
- }
- }
-